//
//  AssetBController.m
//  FinancialProduct
//
//  Created by Stella on 2017/9/4.
//  Copyright © 2017年 maq. All rights reserved.
//

#import "HandleNetProduct.h"
#import "MyAccountCell.h"
#import "ReportController.h"
#import "ReminderWebController.h"
#import "CKPuslichTool.h"
//#import "DBCharts.h"
#import "Header.h"
#import "MyScrollView.h"
#import "AssetBController.h"
#import "RecordListController.h"
#import "UserBankAccountController.h"
#import "TransactionInfoCell.h"
#import "UIColor+NN.h"
#import "UserModel.h"
#import "XLineChartView.h"
#import "DBHelper.h"
#import "HistoryRoseController.h"
#import "InspectController.h"

@interface AssetBController (){
    BOOL isSelect;
}
@property(nonatomic,strong)NSMutableArray *DataArray;
@property(nonatomic,strong)NSMutableArray *infoArray;
@property (weak, nonatomic) IBOutlet UIView *middleView;
@property (weak, nonatomic) IBOutlet UITableView *topTable;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topTableH;
@property (weak, nonatomic) IBOutlet UITableView *middleTable;
@property (weak, nonatomic) IBOutlet UITableView *bottomTable;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomh;
@property (weak, nonatomic) IBOutlet UILabel *lineName;
@property(nonatomic,strong)NSDictionary *info;
@property(nonatomic,strong)NSArray *LineDataArray;
@property(nonatomic,strong)NSArray *nameDataArray;
@property (weak, nonatomic) IBOutlet UIView *chooseTableView;
@property (weak, nonatomic) IBOutlet UIView *chooseView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *remindViewHeight;
@property (weak, nonatomic) IBOutlet UIButton *chooseBt;
@property (weak, nonatomic) IBOutlet UILabel *totalName2;
@property (weak, nonatomic) IBOutlet UILabel *chooseLa;
@property (weak, nonatomic) IBOutlet UILabel *totalName;
@property (weak, nonatomic) IBOutlet UIView *picView;
@property (weak, nonatomic) IBOutlet MyScrollView *mScrollView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *middleTableH;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *pictoTop;
@property (weak, nonatomic) IBOutlet UILabel *line2;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *middleViewH;
@property (weak, nonatomic) IBOutlet UIView *clearView;
@property (weak, nonatomic) IBOutlet UIButton *bottomBtn;

@property (weak, nonatomic) IBOutlet UIView *remindBg;
@property(nonatomic,strong)NSArray *nameArray;


@end

@implementation AssetBController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.bottomTable.rowHeight=50;
    self.topTable.rowHeight=50;
    self.middleTable.estimatedRowHeight=40;
    self.middleTable.rowHeight = UITableViewAutomaticDimension;
//    self.mTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.title=@"详细信息";
    isSelect=NO;
    self.chooseView.hidden=YES;
    self.pictoTop.constant=80;
    _infoArray=[[NSMutableArray alloc] init];
    _DataArray = [[NSMutableArray alloc] init];
    NSLog(@"_infoDic ===%@",_infoDic);
    if ([_infoDic[@"ProductTypeLevel1"] isEqualToString:@"二级市场"]) {
        self.remindViewHeight.constant = 50;
        _remindBg.hidden = NO;
    }else{
        self.remindViewHeight.constant = 0;
        _remindBg.hidden = YES;
    }
    if ([_infoDic[@"Templet"] isEqualToString:@"模板二"]) {
        [self.DataArray removeAllObjects];
        [_infoArray removeAllObjects];
        [self getDetailInfo];
    }else if ([_infoDic[@"Templet"] isEqualToString:@"模板三"]) {
        [self.DataArray removeAllObjects];
        [_DataArray addObjectsFromArray:@[@"产品成立/开放日",@"投资金额",@"投资份额",@"产品期限",@"已分配金额",@"存续份额"]];
        [self.infoArray removeAllObjects];
        [_infoArray addObjectsFromArray:@[self.infoDic[@"qPlacementDate"],
                                          self.infoDic[@"qInitalAmount"],
                                          self.infoDic[@"qInitialshare"],
                                          self.infoDic[@"ProductPeriod"],
                                          self.infoDic[@"qBJAmt"],
                                          self.infoDic[@"qSurvivingShare"]]];
        [self getDetailInfo];
    }else{
        //模板四
        
        [self getDetailInfo];
        
    }
    
    self.topTableH.constant=self.DataArray.count*50;
    if ([_infoDic[@"ProductTypeLevel1"] isEqualToString:@"一级市场"]) {
        //一级市场产品下所有净值相关的展示隐藏
        
        if ([_infoDic[@"ContractStatus"] isEqualToString:@"存续"]) {
            _nameArray = @[@"交易记录",@"受益账户",@"产品报告",@"产品公告"];
        }else{
            _nameArray = @[@"交易记录",@"受益账户"];
        }
        self.bottomh.constant=50*_nameArray.count;
        self.middleView.hidden=YES;
        self.middleViewH.constant=0;
        [self.bottomTable reloadData];
    }else{
        self.middleViewH.constant=320;
        if ([_infoDic[@"ContractStatus"] isEqualToString:@"存续"]) {
            _nameArray = @[@"历史净值",@"交易记录",@"受益账户",@"产品报告",@"产品公告"];
        }else{
            _nameArray = @[@"历史净值",@"交易记录",@"受益账户"];
        }
        UIViewSetRadius(self.chooseBt, 0, 0.5, [UIColor lightGrayColor]);
        self.LineDataArray=[[NSArray alloc] init];
        self.chooseTableView.hidden=YES;
        self.bottomh.constant=50*_nameArray.count;
        [self.bottomTable reloadData];
        [self getLineData];
    }
    
    _bottomBtn.hidden = YES;
    if ([_infoDic[@"ProductTypeLevel1"] isEqualToString:@"二级市场"]) {
        _bottomBtn.hidden = NO;
    }
}
#pragma mark - 温馨提示
- (IBAction)goReminder:(id)sender {
    [HandleNetProduct GetReminderUrlWith:@"资产明细" userId:[UserModel getUser].CustomerID Success:^(NSDictionary *data) {
        NSLog(@"goReminder===%@",data);
        ReminderWebController *vc = (ReminderWebController *)[CKPuslichTool getViewControllerFromStroyBoard:@"My" viewID:@"ReminderWebController"];
        vc.filePath = data[@"path"];
        [vc setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
        [vc setModalPresentationStyle:UIModalPresentationOverFullScreen];
        [self presentViewController:vc animated:YES completion:nil];
    } Failure:^(NSString *errorInfo) {
        
    }];
   
    
}

-(void)getDetailInfo{
    /*
     * Contractno 产品合同号
     * CurrencyType 币种
     * Templet 模板
     */
    UserModel *model=[UserModel getUser];
    int mid=[model.CustomerID intValue];
    NSDictionary *params=@{@"AAAMethodName":@"Prodetail",@"CustomerID":@(mid),
                           
                           @"Contractno":self.infoDic[@"Contractno"],
                           @"CurrencyType":self.infoDic[@"CurrencyType"],
                           @"Templet":self.infoDic[@"Templet"]};
    NSLog(@"params===%@",params);
    [HandleNetProduct getListforParams:params Success:^(NSArray *data) {
        
        if (data.count>0) {
            NSDictionary *dicct=data[0];
            /***
             **/
            self.info=dicct;
            if ([_infoDic[@"Templet"] isEqualToString:@"模板二"]) {
                NSLog(@"self.info==%@",self.info);
                [_DataArray addObjectsFromArray:@[@"累计投资金额",@"累计投资单位净值",@"累计投资份额",@"累计赎回份额",@"累计赎回金额",@"存续基金份额",@"最新单位净值",@"存续资金规模",@"单位份额分红金额",@"收益率"]];
                
                [_infoArray addObjectsFromArray:@[dicct[@"qInitalAmount"],
                                                  dicct[@"NetCount"],
                                                  dicct[@"qInitialshare"],
                                                  dicct[@"qRedeemshare"],
                                                  dicct[@"qRedeemAmount"],
                                                  dicct[@"qSurvivingShare"],
                                                  dicct[@"Net"],
                                                  dicct[@"qSurvivingAmount"],
                                                  dicct[@"FHAmount"],
                                                  dicct[@"SYLV"]]];
                if ([dicct[@"Isshow"] isEqualToString:@"是"]) {
                    [_DataArray addObject:@"数据截止日期"];
                    [_infoArray addObject:dicct[@"DatacutoffDate"]];
                }
            }else if ([_infoDic[@"Templet"] isEqualToString:@"模板四"]){
                //模板四
                if ([dicct[@"LastPurchaseOpenDay"] length]>0) {
                     //模板四一
                    [_DataArray removeAllObjects];
                    [_DataArray addObjectsFromArray:@[@"产品成立/开放日",@"初始投资金额",@"初始投资份额",@"成立单位净值",@"产品期限",@"业绩比较基准",@"预计清算日期",@"已分配金额",@"最近开放日期",@"净值"]];
                    [_infoArray removeAllObjects];
                    [_infoArray addObjectsFromArray:@[dicct[@"PurchaseOpenDay"],
                                                      dicct[@"InitalAmount"],
                                                      dicct[@"Initialshare"],
                                                      dicct[@"Net"],
                                                      dicct[@"ProductPeriodShow"],
                                                      dicct[@"ExpectedRate"],
                                                      dicct[@"AExpectedDueDate"],
                                                      dicct[@"BJAmt"],
                                                      dicct[@"LastPurchaseOpenDay"],
                                                      dicct[@"LastNet"]]];
                   
                }else{
                
                     //模板四二
                    [_DataArray removeAllObjects];
                    [_DataArray addObjectsFromArray:@[@"产品成立/开放日",@"初始投资金额",@"初始投资份额",@"成立单位净值",@"产品期限",@"业绩比较基准",@"预计清算日期",@"已分配金额",@"清算日",@"净值"]];
                    [_infoArray removeAllObjects];
                    [_infoArray addObjectsFromArray:@[dicct[@"PurchaseOpenDay"],
                                                      dicct[@"InitalAmount"],
                                                      dicct[@"Initialshare"],
                                                      dicct[@"Net"],
                                                      dicct[@"ProductPeriodShow"],
                                                      dicct[@"ExpectedRate"],
                                                      dicct[@"AExpectedDueDate"],
                                                      dicct[@"BJAmt"],
                                                      dicct[@"ClearTime"],
                                                      dicct[@"DocDateNet"]]];
                    
                }

            }
        }
        [self.topTable reloadData];
        self.topTableH.constant=self.DataArray.count*50;
    } Failure:^(NSString *errorInfo) {
    }];
}
- (IBAction)chooseNames:(UIButton *)sender {
    sender.selected=!sender.selected;
    self.chooseTableView.hidden=NO;
//    self.navigationController.navigationBar.alpha=0.4;
//    self.navigationController.navigationBar.userInteractionEnabled=NO;
    
    [self.navigationController.navigationBar setUserInteractionEnabled:NO];
    self.navigationController.navigationBar.alpha=0.5;
}

-(void)getLineData{
//    NSLog(@"self.infoDic==%@",self.infoDic);
    int subid=[self.infoDic[@"Subproductid"] intValue];
//    int mid=[self.infoDic[@"ProductID"] intValue];
    NSDictionary *params=@{@"AAAMethodName":@"ProductNet",
                           @"CustomerID":[UserModel getUser].CustomerID,
                           @"SubProductId":@(subid)};//@"ProductId":@(mid)
     NSLog(@"params===%@",params);
    [HandleNetProduct getInvestAssetListforParams:params Success:^(NSArray *data) {
        NSLog(@"getLineData===%@",data);
        
        if (data.count>0) {
            NSDictionary *one=data[0];
            
            if ([one[@"IsSelect"] isEqualToString:@"Yes"]) {
                /**
                 IsSelect = Yes;
                 SubProductId = 621;
                 SubProductName = "\U6de1\U6c34\U6cc9-\U9646\U5bb6\U5634\U8d22\U5bcc\U57fa\U91d12\U671f2015/04/30\U5f00\U653e\U65e5";
                 **/
                isSelect=YES;
                self.nameDataArray=data;
                if (_nameDataArray.count *30 >Main_Screen_Height -120) {
                    _middleTableH.constant = Main_Screen_Height -120;
                }else{
                    _middleTableH.constant = _nameDataArray.count *30;
                }
                
                self.chooseView.hidden=NO;
                self.pictoTop.constant=110;
                self.middleViewH.constant=360;
                [self.middleTable reloadData];
                self.totalName.text=self.nameDataArray[0][@"SubProductName"];
                [self getLineDataWithSubId:self.nameDataArray[0][@"SubProductId"]];
                
            }else{
                /***
                 DocDate = "2016/1/15 0:00:00";
                 IsSelect = No;
                 Net = 1;
                 SumNet = 1;
                 SumRose = 0;
                 ***/
                isSelect=NO;
                self.chooseView.hidden=YES;
                self.pictoTop.constant=80;
             
                self.totalName2.text=self.infoDic[@"ProductName"];
                self.LineDataArray=data;
                if (data.count>0) {
                    self.middleView.hidden=NO;
                    self.middleViewH.constant=320;
                }else{
                    
                    if ([_infoDic[@"ContractStatus"] isEqualToString:@"存续"]) {
                        _nameArray = @[@"交易记录",@"受益账户",@"产品报告",@"产品公告"];
                    }else{
                        _nameArray = @[@"交易记录",@"受益账户"];
                    }
                    self.bottomh.constant=50*_nameArray.count;
                    self.middleView.hidden=YES;
                    self.middleViewH.constant=0;
                    [self.bottomTable reloadData];
                }

                [self sortMyData];
            }
            
        }
        
    } Failure:^(NSString *errorInfo) {
        
    }];
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    UITouch *touch=[touches anyObject];
    CGPoint point = [touch locationInView:self.middleTable];
    if (point.x < 0 ||point.x > self.middleTable.bounds.size.width || point.y < 0 ||point.y > self.middleTable.bounds.size.height) {
        self.chooseBt.selected=NO;
        self.chooseTableView.hidden=YES;
        
        [self.navigationController.navigationBar setUserInteractionEnabled:YES];
        self.navigationController.navigationBar.alpha=1;
    }
    
}

#pragma mark - Table view data source
//- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
//{
//
//    if (tableView==_middleTable) {
//        return 50;
//    }
//    return 50;
//    
//}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    
    return 1;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    if (tableView==_topTable) {
        return self.DataArray.count;
    }else if (tableView==_bottomTable){
        return self.nameArray.count;
    }else{
        return self.nameDataArray.count;
    }
  
    
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView==_topTable) {
        MyAccountCell *cell=[tableView dequeueReusableCellWithIdentifier:@"MyAccountCell0" forIndexPath:indexPath];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        cell.accessoryType=UITableViewCellAccessoryNone;
        cell.unit.text=@"";
        
        if ([_infoDic[@"Templet"] isEqualToString:@"模板二"]) {
           
            if (indexPath.row==0||indexPath.row==4||indexPath.row==7) {
                cell.unit.text=@"万元";
            }
            if (indexPath.row==8) {
                cell.unit.text=@"元";
            }
            if (indexPath.row==2||indexPath.row==3||indexPath.row==5) {
                cell.unit.text=@"份";
            }
           
        }else if ([_infoDic[@"Templet"] isEqualToString:@"模板三"]) {
            
            if (indexPath.row==1||indexPath.row==4) {
                cell.unit.text=@"万元";
            }
            if (indexPath.row==2||indexPath.row==5) {
                cell.unit.text=@"份";
            }

        }else{
            //模板四
            if (indexPath.row==1||indexPath.row==2||indexPath.row==7) {
                cell.unit.text=@"万元";
            }
            if (indexPath.row==2) {
                cell.unit.text=@"份";
            }
            if (indexPath.row==5) {
                cell.unit.text=@"%";
            }
        }
        
        
        cell.NameLabel.text=self.DataArray[indexPath.row];
        cell.RightLabel.text=self.infoArray[indexPath.row];
        return cell;
    }else if (tableView==_bottomTable) {
        MyAccountCell *cell=[tableView dequeueReusableCellWithIdentifier:@"MyAccountCell" forIndexPath:indexPath];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        cell.accessoryType=UITableViewCellAccessoryNone;
        cell.NameLabel.text=self.nameArray[indexPath.row];
        return cell;
    }else{
        TransactionInfoCell *cell=[tableView dequeueReusableCellWithIdentifier:@"TransactionInfoCell" forIndexPath:indexPath];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        cell.accessoryType=UITableViewCellAccessoryNone;
        cell.nameLa.text=_nameDataArray[indexPath.row][@"SubProductName"];
        [cell layoutIfNeeded];
        return cell;

    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
   
    return 0.01;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
//    if (tableView == _topTable) {
//        return 44;
//    }
    return 0.01;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (tableView==_bottomTable){
        MyAccountCell *cell= [tableView cellForRowAtIndexPath:indexPath];
        if ([cell.NameLabel.text isEqualToString:@"历史净值"]) {
            HistoryRoseController *vc=(HistoryRoseController *)[CKPuslichTool getViewControllerFromStroyBoard:@"My" viewID:@"HistoryRoseController"];
            vc.dataArray=self.LineDataArray;
            [self.navigationController pushViewController:vc animated:YES];
        }else if ([cell.NameLabel.text isEqualToString:@"交易记录"]) {
            RecordListController *vc=(RecordListController *)[CKPuslichTool getViewControllerFromStroyBoard:@"My" viewID:@"RecordListController"];
            vc.infoDic=self.infoDic;
            [self.navigationController pushViewController:vc animated:YES];
        }else if ([cell.NameLabel.text isEqualToString:@"受益账户"]) {
            UserBankAccountController *vc=(UserBankAccountController *)[CKPuslichTool getViewControllerFromStroyBoard:@"My" viewID:@"UserBankAccountController"];
            vc.infoDic=self.info;
            [self.navigationController pushViewController:vc animated:YES];
        }else {
            ReportController *vc=(ReportController *)[CKPuslichTool getViewControllerFromStroyBoard:@"My" viewID:@"ReportController"];
          
            if ([cell.NameLabel.text isEqualToString:@"产品报告"]) {
                vc.title=@"产品报告";
            }else{
                vc.title=@"产品公告";
            }
            
           vc.ProductId=self.infoDic[@"ProductID"];
            [self.navigationController pushViewController:vc animated:YES];
        }
        
//        if (self.middleView.hidden) {
//            switch (indexPath.row) {
//
//                case 0://交易记录
//                {
//
//                }
//                    break;
//                case 1://受益账户
//                {
//
//                }
//                    break;
//
//                default:
//                    break;
//            }
//        }else{
//            switch (indexPath.row) {
//                case 0://历史净值
//                {
//
//
//                }
//                    break;
//                case 1://交易记录
//                {
//                    RecordListController *vc=(RecordListController *)[CKPuslichTool getViewControllerFromStroyBoard:@"My" viewID:@"RecordListController"];
//                    vc.infoDic=self.infoDic;
//                    [self.navigationController pushViewController:vc animated:YES];
//                }
//                    break;
//                case 2://受益账户
//                {
//                    UserBankAccountController *vc=(UserBankAccountController *)[CKPuslichTool getViewControllerFromStroyBoard:@"My" viewID:@"UserBankAccountController"];
//                    vc.infoDic=self.info;
//                    [self.navigationController pushViewController:vc animated:YES];
//                }
//                    break;
//                default:
//                    break;
//            }
//        }
        
    }else if (tableView==_middleTable){
//        self.middleTable.hidden=YES;
        self.chooseBt.selected=NO;
        self.chooseTableView.hidden=YES;

        [self.navigationController.navigationBar setUserInteractionEnabled:YES];
        self.navigationController.navigationBar.alpha=1;
        
        
        
        self.totalName.text=self.nameDataArray[indexPath.row][@"SubProductName"];
        [self getLineDataWithSubId:self.nameDataArray[indexPath.row][@"SubProductId"]];
    }
    
}

-(void)getLineDataWithSubId:(NSString *)subId{
    NSDictionary *params=@{@"AAAMethodName":@"ProductNetSelect",@"SubProductId":subId};
    [HandleNetProduct getListforParams:params Success:^(NSArray *data) {
        /**
         DocDate = "2016/7/29 0:00:00";
         IsSelect = No;
         Maximum = "55.34";
         Minimum = "-16.22";
         Net = "1.1512";
         Rose = "-6.71";
         SumNet = "1.1512";
         SumRose = "15.12";
         **/
        if (data.count>0) {
            self.LineDataArray=data;
            [self sortMyData];
            self.middleView.hidden=NO;
            self.middleViewH.constant=360;
        }else{
            if ([_infoDic[@"ContractStatus"] isEqualToString:@"存续"]) {
                _nameArray = @[@"交易记录",@"受益账户",@"产品报告",@"产品公告"];
            }else{
                _nameArray = @[@"交易记录",@"受益账户"];
            }
           
            self.middleView.hidden=YES;
            self.middleViewH.constant=0;
            self.bottomh.constant=50*_nameArray.count;
            [self.bottomTable reloadData];
        }
       
   
    } Failure:^(NSString *errorInfo) {
        
    }];
}
-(void)sortMyData{
    self.line2.hidden=YES;
    self.lineName.hidden=YES;
    XLineChartView *chartView = [[XLineChartView alloc] initWithFrame:self.picView.bounds];
    chartView.xAssistLineColor=[UIColor whiteColor];//纵向辅助线颜色
    chartView.strokeLineWidth=1;//线条宽度
    chartView.coordColor=[UIColor lightGrayColor];
    chartView.coordWidth=0.5;//坐标轴颜色
    chartView.yLabNumber=5;//Y分块个数
    chartView.animationEnable=NO;
    chartView.chartType = XChartLineTypeCurve;//设置绘制类型为曲线
    chartView.showDot = NO;   //设置显示圆点
    chartView.gradientEnable = NO;  //设置启用渐变填充
    NSMutableArray *xTitles = [NSMutableArray array];
    NSMutableArray *yValues = [NSMutableArray array];
    
    for (UIView *vc in self.picView.subviews) {
        [vc removeFromSuperview];
    }
    if (self.LineDataArray.count==0) {
        return;
    }
    float max=[self.LineDataArray[0][@"Maximum"] floatValue];
    float min=[self.LineDataArray[0][@"Minimum"] floatValue];
    float sum=max-min;
    if (sum==0) {
        if ([self.LineDataArray[0][@"Reference"] isEqualToString:@"无"]) {
            self.line2.hidden=YES;
            self.lineName.hidden=YES;
        }else{
            self.line2.hidden=NO;
            self.lineName.hidden=NO;
            NSString *nameSS=[NSString stringWithFormat:@"%@增长率",self.LineDataArray[0][@"Reference"]];
            self.lineName.text=nameSS;
        }
        return;
    }
    float sizeH = sum/5;
    //    //NSLog(@"sizeH==%d",sizeH);
    NSString *hh1=[NSString stringWithFormat:@"%.2f",min];
    NSString *hh2=[NSString stringWithFormat:@"%.2f",min+sizeH];
    NSString *hh3=[NSString stringWithFormat:@"%.2f",min+sizeH*2];
    NSString *hh4=[NSString stringWithFormat:@"%.2f",min+sizeH*3];
    NSString *hh5=[NSString stringWithFormat:@"%.2f",min+sizeH*4];
    NSString *hh6=[NSString stringWithFormat:@"%.2f",max];
    NSMutableArray *leftdataA = [NSMutableArray new];
    [leftdataA addObject:hh1];
    [leftdataA addObject:hh2];
    [leftdataA addObject:hh3];
    [leftdataA addObject:hh4];
    [leftdataA addObject:hh5];
    [leftdataA addObject:hh6];
    NSMutableArray* chartData = [NSMutableArray arrayWithCapacity:self.LineDataArray.count];
    NSMutableArray* chartData2 = [NSMutableArray arrayWithCapacity:self.LineDataArray.count];
    NSMutableArray* chartData3 = [NSMutableArray arrayWithCapacity:self.LineDataArray.count];
    
    NSArray* reversedArray = [[self.LineDataArray reverseObjectEnumerator] allObjects];
    
    for (int i=0; i<reversedArray.count; i++) {
        
        [chartData addObject:reversedArray[i][@"SumRose"]];
        [chartData2 addObject:reversedArray[i][@"Rose"]];
        [xTitles addObject:@""];
        NSDate *dateTime =  [DBHelper dateFromCustomString:reversedArray[i][@"DocDate"] format:@"yyyy/MM/dd HH:mm:ss"];
        NSString *time = [DBHelper stringFromCustomFormatDate:dateTime format:@"yyyy-MM-dd"];
        [chartData3 addObject:time?time:reversedArray[i][@"DocDate"]];
    }
    [yValues addObject:chartData];
    NSArray *nameTitleArray=[NSArray array];
    NSArray *colorA = [NSArray array];
    
    if ([self.LineDataArray[0][@"Reference"] isEqualToString:@"无"]) {
        self.line2.hidden=YES;
        self.lineName.hidden=YES;
        colorA=@[[UIColor colorWithHexString:@"#65AFF7"]];
        nameTitleArray=@[@"产品净值增长率"];
    }else{
        self.line2.hidden=NO;
        self.lineName.hidden=NO;
        NSString *nameSS=[NSString stringWithFormat:@"%@增长率",self.LineDataArray[0][@"Reference"]];
        self.lineName.text=nameSS;
        [yValues addObject:chartData2];
        colorA=@[[UIColor colorWithHexString:@"#65AFF7"],[UIColor blackColor]];
        nameTitleArray=@[@"产品净值增长率",nameSS];
    }
    
    
    chartView.chartColors=colorA;
    chartView.xTitles = chartData3;    //设置X
    chartView.yValuesArray = yValues;  //设置Y
    chartView.yNameArr=leftdataA;
    chartView.xDateArrays=chartData3;
    chartView.dataNameArr=nameTitleArray;
    chartView.markerLineColor=[UIColor colorWithHexString:@"#BB3535"];
    chartView.scaleType=XChartViewScaleTypeNone;
    [self.picView addSubview:chartView];
    [chartView strokeChart];  //绘制曲线
}

- (IBAction)clickJianShiAction:(UIButton *)sender {
    InspectController *vc=(InspectController *)[CKPuslichTool getViewControllerFromStroyBoard:@"My" viewID:@"InspectController"];
    vc.productId = _infoDic[@"ProductID"];
    vc.customerID = _infoDic[@"CustomerID"];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
